<script setup>
import { ref } from "vue";

const props = defineProps({
  textList: { type: Array },
  columns: { type: Array },
  total: Number,
  baominginformation: Boolean,
  xinadd: {
    type: Boolean,
    default: true,
  },
});
console.log(props);

const emit = defineEmits([
  "SearchValue",
  "add",
  "PageType",
  "delete",
  "edit",
  "baoming",
  "VIPbaoming",
]);

// 查询
const SearchValue = ref("");
const search = () => {
  emit("SearchValue", SearchValue);
  SearchValue.value = "";
};

// 页码
const handleCurrentChange = (page) => {
  // console.log(page);
  emit("PageType", page); // 触发父组件事件
};
</script>

<template>
  <div class="hygl">
    <div class="hygl-top">
      <el-input
        v-model="SearchValue"
        style="width: 240px"
        placeholder="请输入查询参数"
      />
      <el-button type="primary" style="margin-left: 8px" @click="search"
        >查询</el-button
      ><el-button type="primary" style="margin-left: 8px" @click="search"
        >重置</el-button
      >
      <el-button type="primary" @click="$emit('add', null)" v-if="props.xinadd"
        >新增</el-button
      >
    </div>

    <el-table :data="props.textList" border style="width: 100%">
      <!-- 遍历渲染列 -->
      <el-table-column
        v-for="(col, index) in props.columns"
        :key="index"
        :prop="col.prop"
        :label="col.label"
        :width="col.width"
      >
        <!-- 特殊列：头像 -->
        <template #default="scope" v-if="col.type === 'image'">
          <el-image
            style="width: 50px; height: 50px"
            :src="scope.row.hyimg"
          ></el-image>
        </template>

        <!-- 特殊列：操作 -->
        <template #default="scope" v-if="col.type === 'action1'">
          <el-button type="primary" @click="$emit('VIPbaoming', scope.row)"
            >报名</el-button
          ></template
        >
        <template #default="scope" v-if="col.type === 'action'">
          <el-button
            type="primary"
            v-if="baominginformation"
            @click="$emit('baoming', scope.row)"
            >报名信息</el-button
          >
          <el-button type="primary" @click="$emit('edit', scope.row)"
            >编辑</el-button
          >

          <el-button type="danger" @click="$emit('delete', scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="hygl-button">
      <el-pagination
        background
        layout="prev, pager, next"
        :total="total"
        :page-size="5"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<style scoped lang="scss">
:deep() {
  .el-pagination {
    justify-content: flex-end;
  }
}
.hygl {
  height: 100%;
  background-color: #fff;
  .hygl-top {
    text-align: center;
    padding: 8px;
  }
  .hygl-button {
    padding-top: 8px;
  }
}
</style>
